#include "clientstate.h"

namespace GLC {

void ClientState::loadModelView(const mat4d &matrix)
{
    glLoadMatrixd(matrix);
}

void ClientState::loadProjection(const mat4d &matrix)
{
    glMatrixMode(GL_PROJECTION);
    glLoadMatrixd(matrix);
    glMatrixMode(GL_MODELVIEW);
}

void ClientState::resetViewport(int x, int y, unsigned width, unsigned height)
{
    glViewport(x, y, width, height);
}

void ClientState::getModelView(mat4d &matrix)
{
    glGetDoublev(GL_MODELVIEW_MATRIX, matrix);
}

void ClientState::getProjection(mat4d &matrix)
{
    glGetDoublev(GL_PROJECTION_MATRIX, matrix);
}

void ClientState::getViewport(int destination[])
{
    if (sizeof(int) != sizeof(GLint))
    {
        GLint temp[4];
        glGetIntegerv(GL_VIEWPORT, temp);
        for (int i = 0; i < 4; ++i)
        {
            destination[i] = temp[i];
        }
    }
    else
    {
        glGetIntegerv(GL_VIEWPORT, destination);
    }
}

} // namespace GLC
